package com.example.demo2.mapper;

import com.example.demo2.entity.answerRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface Answermapper {
    @Insert("insert into answerrecord(openID,correctCount,errorCount,score,time) values (#{openID},#{correctCount},#{errorCount},#{score},#{time})")
    void saveanswer(answerRecord answerRecord);
    @Select("select * from answerrecord where openID = #{openID} order by time desc")
    @Results(id="AnswerMap", value={
            @Result(column = "openID",property = "openID",javaType = String.class),
            @Result(column = "correctCount",property = "correctCount",javaType = Integer.class),
            @Result(column = "errorCount",property = "errorCount",javaType = Integer.class),
            @Result(column = "score",property = "score",javaType = Integer.class),
            @Result(column = "time",property = "time")


    })
    List<answerRecord> getanswerRecord(String openID);
    @Select("select openID,correctCount,errorCount,max(score) as score,time from answerrecord GROUP BY openID order by score desc")
    @ResultMap(value = "AnswerMap")
    List<answerRecord> getrank();
}
